{{Extend "db/index"}}
{{Block "title"}}{{"数据库"|T}}: {{Stored.dbName}} - {{Super}}{{/Block}}
{{Block "breadcrumb"}}
{{Super}}
<li><a href="{{dbMgrURL "listTable" Stored.dbName}}" data-pjax="#pcont" data-keepjs="true">{{"数据库"|T}}: {{Stored.dbName}}</a></li>
<li class="active">{{"表"|T}}: {{Stored.table}}</li>
{{/Block}}
{{Block "main"}}
{{$table := Stored.table}}
<div class="row">
    <div class="col-md-12">
        {{Include "db/mysql/results"}}
        <div class="block-flat">
          <div class="header">
            <div class="btn-group pull-right">
			<a href="{{dbMgrURL "listData" Stored.dbName $table}}" class="btn btn-default" data-pjax="#pcont" data-keepjs="true">
				<i class="fa fa-list"></i>
				{{"查看数据"|T}}
			</a>
			<a href="{{dbMgrURL "createData" Stored.dbName $table}}" class="btn btn-default" data-pjax="#pcont" data-keepjs="true">
				<i class="fa fa-plus"></i>
				{{"新建数据"|T}}
			</a>
			<a href="{{dbMgrURL "modifyTable" Stored.dbName $table}}" class="btn btn-default" data-pjax="#pcont" data-keepjs="true">
				<i class="fa fa-pencil"></i>
				{{"修改表"|T}}
			</a>
            </div>
            <h3>{{"表结构"|T}}: {{$table}}</h3>
            {{if Stored.tableStatus.Comment.Valid}}
            <div class="table-comment">{{"注释"|T}}: {{Stored.tableStatus.Comment.String}}</div>
            {{end}}
          </div>
          <div class="content">
             <div class="table-responsive">
				<table class="table no-border hover blue">
					<thead class="no-border">
						<tr>
							<th><strong>{{"列"|T}}</strong></th>
							<th><strong>{{"类型"|T}}</strong></th>
							<th><strong>{{"注释"|T}}</strong></th>
						</tr>
					</thead>
					<tbody class="no-border-x" id="tbody-content">
                        {{range $k,$v := Stored.postFields}}
						<tr>
                            <td><b>{{$v.Field}}</b></td>
							<td title="{{$v.Type}}">
                                {{$v.Full_type}}
                                {{if $v.Null}}<span>NULL</span>{{end}}
                                {{if $v.AutoIncrement.Valid}}<em>{{"自动增量"|T}}</em>{{end}}
                                {{if $v.Default.Valid}}[<b>{{$v.Default.String}}</b>]{{end}}
                            </td>
							<td>{{$v.Comment}}</td>
						</tr>
                        {{end}}
					</tbody>
				</table>		
			    </div>
          </div><!-- /.content -->
        </div><!-- /.block-flat -->
{{if not Stored.tableStatus.IsView}}
        <div class="block-flat">
          <div class="header">	
            <h3>{{"索引"|T}}</h3>
          </div>
          <div class="content">
             <div class="table-responsive">
				<table class="table no-border hover blue">
					<thead class="no-border">
						<tr>
							<th><strong>{{"类型"|T}}</strong></th>
							<th><strong>{{"列"|T}}</strong></th>
						</tr>
					</thead>
					<tbody class="no-border-x" id="tbody-content">
                        {{range $k,$v := Stored.indexes}}
						<tr>
                            <td><b>{{$v.Type}}</b></td>
							<td>
                                {{range $i,$r := $v.Columns}}
                                {{if gt $i 0}}, {{end}}
                                <span>{{$r}}</span>
                                {{$length := index $v.Lengths $i}}
                                {{$desc := index $v.Descs $i}}
                                {{if $length}}({{$length}}){{end}}
                                {{if $desc}} DESC{{end}}
                                {{end}}
                            </td>
						</tr>
                        {{end}}
					</tbody>
				</table>
                <a href="{{dbMgrURL "indexes" Stored.dbName $table}}" data-pjax="#pcont" data-keepjs="true">{{"修改索引"|T}}</a>	
			    </div>
          </div><!-- /.content -->
        </div><!-- /.block-flat -->
{{end}}

{{if Stored.tableStatus.FKSupport Stored.version}}
        <div class="block-flat">
          <div class="header">	
            <h3>{{"外键"|T}}</h3>
          </div>
          <div class="content">
             <div class="table-responsive">
				<table class="table no-border hover blue">
					<thead class="no-border">
						<tr>
                            <th><strong>{{"Source"|T}}</strong>({{"当前表字段"|T}})</th>
							<th><strong>{{"Target"|T}}</strong>({{"关联字段"|T}})</th>
							<th><strong>{{"ON DELETE"|T}}</strong></th>
							<th><strong>{{"ON UPDATE"|T}}</strong></th>
							<th style="width:50px"><strong></strong></th>
						</tr>
					</thead>
					<tbody class="no-border-x" id="tbody-content">
                        {{range $k,$v := Stored.foreignKeys}}
						<tr>
                            <td>
                                {{range $i, $r := $v.Source}}
                                {{if gt $i 0}}, {{end}}
                                <b>{{$r}}</b>
                                {{end}}
                            </td>
							<td>
                                {{if $v.Database}}{{$v.Database}}.{{end}}
                                {{$v.Table}}
                                (
                                {{range $i, $r := $v.Target}}
                                {{if gt $i 0}}, {{end}}
                                <b>{{$r}}</b>
                                {{end}}
                                )
                            </td>
							<td>{{$v.OnDelete}}</td>
							<td>{{$v.OnUpdate}}</td>
                            <td><a href="{{dbMgrURL "foreign" Stored.dbName $table}}&name={{$v.Name}}" class="label label-primary" data-pjax="#pcont" data-keepjs="true"><i class="fa fa-pencil"></i></a></td>
						</tr>
                        {{end}}
					</tbody>
				</table>
                <a href="{{dbMgrURL "foreign" Stored.dbName $table}}" data-pjax="#pcont" data-keepjs="true">{{"添加外键"|T}}</a>	
			    </div>
          </div><!-- /.content -->
        </div><!-- /.block-flat -->
{{end}}

{{if Stored.supportTrigger}}
        <div class="block-flat">
          <div class="header">	
            <h3>{{"触发器"|T}}</h3>
          </div>
          <div class="content">
             <div class="table-responsive">
				<table class="table no-border hover blue">
					<thead class="no-border">
						<tr>
                            <th><strong>{{"Timing"|T}}</strong></th>
							<th><strong>{{"Event"|T}}</strong></th>
							<th><strong>{{"Trigger"|T}}</strong></th>
							<th style="width:50px"><strong></strong></th>
						</tr>
					</thead>
					<tbody class="no-border-x" id="tbody-content">
                        {{range $k,$v := Stored.triggers}}
						<tr>
							<td>{{$v.Timing.String}}</td>
							<td>{{$v.Event.String}}</td>
							<td>{{$v.Trigger.String}}</td>
                            <td><a href="{{dbMgrURL "trigger" Stored.dbName $table}}&name={{$v.Trigger.String}}" class="label label-primary" data-pjax="#pcont" data-keepjs="true"><i class="fa fa-pencil"></i></a></td>
						</tr>
                        {{end}}
					</tbody>
				</table>
                <a href="{{dbMgrURL "trigger" Stored.dbName $table}}" data-pjax="#pcont" data-keepjs="true">{{"创建触发器"|T}}</a>	
			    </div>
          </div><!-- /.content -->
        </div><!-- /.block-flat -->
{{end}}

    </div>
</div>
{{/Block}}

{{Block "footer"}}
{{Super}}
<script>
</script>
{{/Block}}